<meta charset="UTF-8">
<title>Insert title here</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/bootstrap-table.min.css" rel="stylesheet" >
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/bootstrap-table.min.js"></script>
<script src="../js/bootstrap-table-zh-CN.js"></script>
<script src="../js/swift.js"></script>
</head>
<body>
<div class="container-fluid">
        <div id="toolbar" class="btn-group">
            <a href="#">
	            <button type="button" id="add" class="btn btn-default" >
	                <i class="glyphicon glyphicon-plus"></i>添加
	            </button>
            </a>
            <a>
	            <button type="button" onclick="deleteHr();" id="delete" class="btn btn-default">
	                <i class="glyphicon glyphicon-trash"></i>删除
	            </button>
            </a>
            <a>
            	<button type="button" onclick="deleteHr();" id="delete" class="btn btn-default">
                	<i class="glyphicon glyphicon-trash"></i>扩展功能
           		</button>
            </a>
             <a>
            	<button type="button" onclick="deleteHr();" id="delete" class="btn btn-default">
                	<i class="glyphicon glyphicon-trash"></i>保存
           		</button>
            </a>
        </div>
        <table id="table1"></table>
</div>
<script type="text/javascript">

$('#table1').bootstrapTable({
//     url: '/html/json/bt4.json',
    url: '/data/bt4',
    method: 'get',                      //请求方式（*）
	toolbar: '#toolbar',                //工具按钮用哪个容器
	striped: true,                      //是否显示行间隔色
	cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
	pagination: true,                   //是否显示分页（*）
	sortable: false,                     //是否启用排序
	sortOrder: "asc",                   //排序方式
	//queryParams: oTableInit.queryParams,//传递参数（*）
// 	sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
	pageNumber: 1,                       //初始化加载第一页，默认第一页
	pageSize: 10,                       //每页的记录行数（*）
	undefinedText : '-',
    pageList : [ 5, 10, 20 ],  
    showColumns : true, // 显示隐藏列  
//     showRefresh : true, // 显示刷新按钮  
    columns: [{
        field: 'id',
        title: 'Item ID'
    }, {
        field: 'name',
        title: 'Item Name'
    }, {
        field: 'price',
        title: 'Item Price'
    }, ],
    onCheck:function(){  
        buttonControl('#mytb2','#edit','#delete');  
    },  
    onCheckAll:function(){  
        buttonControl('#mytb2','#edit','#delete');  
    },  
    onUncheckAll:function(){  
        buttonControl('#mytb2','#edit','#delete');  
    },  
    onUncheck:function(){  
        buttonControl('#mytb2','#edit','#delete');  
    }  
});
/** 刷新页面 */  
function refresh() {  
    $('#mytb2').bootstrapTable('refresh');  
}  
/**查询条件与分页数据 */  
function queryParams(pageReqeust) {  
    pageReqeust.enabled = $("#enabled").val();  
    pageReqeust.querys = $("#querys").val();  
    pageReqeust.pageNo = this.offset;  
    pageReqeust.pageSize = this.pageNumber;  
    return pageReqeust;  
}  
/** 编辑数据 */  
function editHr() {  
    var selectRow = $("#mytb2").bootstrapTable('getSelections');  
    if (selectRow.length != 1) {  
        layer.alert('请选择并只能选择一条数据进行编辑！', {icon: 2});  
        return false;  
    } else {  
//         window.location = createUrl("admin/hrEmployee/view?username=" + selectRow[0].userName);  
    }  
}  
/** 
 * 删除数据 
 */  
function deleteHr() {  
    var hrs = $("#mytb2").bootstrapTable('getSelections');  
    if (hrs.length < 1) {  
        layer.alert('请选择一条或多条数据进行删除！', {icon: 2});  
    } else {  
        layer.confirm('确定要删除所选数据？', {icon: 3, title:'提示'}, function(){  
            var userNames = [];  
            for (var i=0;i<hrs.length;i++){  
                    userNames.push(hrs[i].userName);  
            }  
            $.ajax({  
                url:'../../../admin/hrEmployee/delete',  
                traditional: true,  //阻止深度序列化，向后台传送数组  
                data:{userNames:userNames},  
                contentType:'application/json',  
                success:function(msg){  
                    if(msg.success){  
                        layer.alert(msg.msg,{icon:1});  
                    }else{  
                        layer.alert(msg.msg,{icon:2});  
                    }  
                    refresh();  
                    $("#edit").attr({"disabled":"disabled"});  
                    $("#delete").attr({"disabled":"disabled"});  
                }  
            })  
          });  
    }  
}  
</script>
</body>
</html>